<template>
	<view class="container">
		<view class="main-header"
			:style="{ height: platform == 'H5' ? '260rpx' : '320rpx', paddingTop: platform == 'H5' ? '0' : '80rpx' }">
			<image class="bg-image" src="/static/user-header.png" mode="scaleToFill"></image>
			<!-- 未登录 -->
			<view class="user-info" @click="handleLogin">
				<view class="user-avatar">
					<avatar-image :url="userInfo.avatar" :width="100" />
				</view>
				<view class="user-content">
					<view class="nick-name">{{userInfo.userName || '未登录'}}</view>
					<view class="login-tips">{{userInfo.mobile || '点击登录账号'}}</view>
				</view>
			</view>
		</view>

		<!-- 我的钱包 -->
		<view class="my-asset">
			<view class="asset-left">
				<view class="asset-left-item" style="max-width: 200rpx;" @click="onTargetWallet">
					<view class="item-value dis-flex flex-x-center">
						<text class="oneline-hide">{{ assets.balance}}</text>
					</view>
					<view class="item-name dis-flex flex-x-center">
						<text>账户余额</text>
					</view>
				</view>
				<view class="asset-left-item" @click="onTargetPoints">
					<view class="item-value dis-flex flex-x-center">
						<text class="oneline-hide">{{ assets.points}}</text>
					</view>
					<view class="item-name dis-flex flex-x-center">
						<text>积分</text>
					</view>
				</view>
				<view class="asset-left-item" @click="onTargetMyCoupon">
					<view class="item-value dis-flex flex-x-center">
						<text class="oneline-hide">{{ assets.coupon}}</text>
					</view>
					<view class="item-name dis-flex flex-x-center">
						<text>优惠券</text>
					</view>
				</view>
			</view>
			<view class="asset-right">
				<view class="asset-right-item" @click="onTargetWallet">
					<view class="item-icon">
						<u-icon size="25" name="/static/package.png"></u-icon>
					</view>
					<view class="item-name dis-flex flex-x-center">
						<text>我的钱包</text>
					</view>
				</view>
			</view>
		</view>
		<!-- 订单操作 -->
		<view class="order-navbar">
			<view class="order-navbar-item" v-for="(item, index) in orderNavbar" :key="index"
				@click="onTargetOrder(item)">
				<view class="item-icon">
					<u-icon size="30" :name="`${item.icon}`"></u-icon>
				</view>
				<view class="item-name">{{ item.name }}</view>
				<view class="item-badge" v-if="item.count && item.count > 0">
					<text v-if="item.count <= 99" class="text">{{ item.count }}</text>
					<text v-else class="text">99+</text>
				</view>
			</view>
		</view>
		<!-- 我的服务 -->
		<view class="my-service">
			<view class="service-title">我的服务</view>
			<view class="service-content">
				<block v-for="(item, index) in service" :key="index">
					<view class="service-item" @click="handleService(item)">
						<view class="item-icon">
							<u-icon size="30" :name="`${item.icon}`"></u-icon>
						</view>
						<view class="item-name">{{ item.name }}</view>
						<view class="item-badge" v-if="item.count && item.count > 0">
							<text v-if="item.count <= 99" class="text">{{ item.count }}</text>
							<text v-else class="text">99+</text>
						</view>
					</view>
				</block>
			</view>
		</view>
	</view>
</template>

<script>
	import AvatarImage from '@/components/avatar-image'
	import platform from '@/utils/platform'
	export default {
		components: {
			AvatarImage
		},
		data() {
			return {
				userInfo: {},
				platform,
				// 是否已登录
				isLogin: false,
				assets: {
					balance: '--',
					points: '--',
					coupon: '--'
				},
				// 订单操作
				orderNavbar: [{
						id: 'all',
						name: '全部订单',
						icon: 'order'
					},
					{
						id: 'payment',
						name: '待支付',
						icon: 'red-packet',
						count: 0
					},
					{
						id: 'delivery',
						name: '待发货',
						icon: 'car',
						count: 0
					},
					{
						id: 'received',
						name: '待收货',
						icon: 'calendar',
						count: 0
					},
				],
				// 我的服务
				service: [{
						id: 'address',
						name: '收货地址',
						icon: '/static/address.png',
						type: 'link',
						url: 'pages/address/index'
					},
					{
						id: 'coupon',
						name: '领券中心',
						icon: '/static/gift.png',
						type: 'link',
						url: 'pages/coupon/index',
						moduleKey: 'market-coupon'
					},
					{
						id: 'myCoupon',
						name: '优惠券',
						icon: '/static/coupon.png',
						type: 'link',
						url: 'pages/my-coupon/index',
						moduleKey: 'market-coupon'
					},
					{
						id: 'refund',
						name: '退换/售后',
						icon: '/static/refund.png',
						type: 'link',
						url: 'pages/refund/index',
						count: 0
					},
					// { id: 'contact', name: '在线客服', icon: '/static/address.png', type: 'contact' },
					{
						id: 'points',
						name: '我的积分',
						icon: '/static/integral.png',
						type: 'link',
						url: 'pages/points/log',
						moduleKey: 'market-points'
					},
					{
						id: 'orderCenter',
						name: '订单中心',
						icon: '/static/order.png',
						type: 'link',
						url: 'pages/order/center'
					},
					{
						id: 'help',
						name: '我的帮助',
						icon: '/static/help.png',
						type: 'link',
						url: 'pages/help/index',
						moduleKey: 'content-help'
					},
				]
			}
		},
		methods: {
			// 跳转到登录页
			handleLogin() {
				!this.isLogin && this.$navTo('pages/login/index')
			},
		},
		onShow(options) {
			this.userInfo = JSON.parse(wx.getStorageSync('userInfo') || '{}')
			console.log(this.userInfo)
		}
	}
</script>

<style lang="scss" scoped>
	// 页面头部
	.main-header {
		// background-color: #FBF7EF;
		position: relative;
		width: 100%;
		height: 280rpx;
		background-size: 100% 100%;
		overflow: hidden;
		display: flex;
		align-items: center;
		padding-left: 30rpx;

		.bg-image {
			position: absolute;
			top: 0;
			left: 0;
			width: 100%;
			height: 100%;
			z-index: 0;
		}

		.user-info {
			display: flex;
			height: 100rpx;
			z-index: 1;

			.user-content {
				display: flex;
				flex-direction: column;
				justify-content: center;
				margin-left: 30rpx;
				color: #c59a46;

				.nick-name {
					font-size: 34rpx;
					font-weight: bold;
					max-width: 300rpx;
				}

				.mobile {
					margin-top: 15rpx;
					font-size: 28rpx;
				}

				.user-grade {
					align-self: baseline;
					display: flex;
					align-items: center;
					background: #3c3c3c;
					margin-top: 12rpx;
					border-radius: 10rpx;
					padding: 4rpx 12rpx;

					.user-grade_icon .image {
						display: block;
						width: 32rpx;
						height: 32rpx;
					}

					.user-grade_name {
						margin-left: 5rpx;
						font-size: 26rpx;
						color: #EEE0C3;
					}

				}

				.login-tips {
					margin-top: 12rpx;
					font-size: 30rpx;
				}

			}
		}
	}

	// 我的钱包
	.my-asset {
		display: flex;
		background: #fff;
		padding: 40rpx 0;

		.asset-right {
			width: 200rpx;
			border-left: 1rpx solid #eee;
		}

		.asset-right-item {
			text-align: center;
			color: #545454;

			.item-icon {
				display: flex;
				justify-content: center;
				font-size: 44rpx;
			}

			.item-name {
				margin-top: 14rpx;
				font-size: 28rpx;
			}

		}

		.asset-left {
			display: flex;
			justify-content: space-around;
			flex: 1;

			.asset-left-item {
				max-width: 183rpx;
				text-align: center;
				color: #666;
				padding: 0 16rpx;

				.item-value {
					font-size: 34rpx;
					color: #fa2209;
				}

				.item-name {
					margin-top: 14rpx;
					font-size: 28rpx;
				}
			}
		}
	}

	// 订单操作
	.order-navbar {
		display: flex;
		margin: 20rpx auto 20rpx auto;
		padding: 20rpx 0 26rpx 0;
		width: 94%;
		box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
		font-size: 30rpx;
		border-radius: 5rpx;
		background: #fff;

		&-item {
			position: relative;
			width: 25%;

			.item-icon {
				display: flex;
				justify-content: center;
				padding: 10rpx 0;
				color: #545454;
				font-size: 44rpx;
			}

			.item-name {
				font-size: 28rpx;
				color: #545454;
				text-align: center;
				margin-right: 10rpx;
			}

		}
	}

	// 角标组件
	.item-badge {
		position: absolute;
		top: 0;
		right: 55rpx;
		// background: $main-bg;
		background: #fa2209;
		color: #fff;
		border-radius: 100%;
		min-width: 38rpx;
		height: 38rpx;
		display: flex;
		justify-content: center;
		align-items: center;
		padding: 1rpx;
		font-size: 24rpx;
	}

	// 我的服务
	.my-service {
		margin: 22rpx auto 22rpx auto;
		padding: 22rpx 0;
		width: 94%;
		box-shadow: 0 1rpx 5rpx 0px rgba(0, 0, 0, 0.05);
		border-radius: 5rpx;
		background: #fff;

		.service-title {
			padding-left: 24rpx;
			margin-bottom: 20rpx;
			font-size: 30rpx;
		}

		.service-content {
			margin-bottom: -20rpx;
			overflow: hidden;

			.service-item {
				position: relative;
				width: 25%;
				float: left;
				margin-bottom: 30rpx;

				.item-icon {
					display: flex;
					justify-content: center;
					padding: 14rpx 0;
					color: #fa2209;
					font-size: 44rpx;
				}

				.item-name {
					font-size: 28rpx;
					color: #545454;
					text-align: center;
				}

			}
		}
	}
</style>
